package com.sh.data.engine.common.util;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.io.IOException;
import java.util.List;

public class CommonFileUtil {
    public static void writeToFile(File file, String content) throws IOException {
        if (StringUtils.isNotBlank(content)) {
            FileUtils.write(file, content, "UTF-8", true);
            FileUtils.write(file, "\n\n", "UTF-8", true);
        }
    }

    public static void writeToFile(File file, List<String>... contents) throws IOException {
        if (null != contents && contents.length > 0) {
            for (List<String> content : contents) {
                if (CollectionUtils.isNotEmpty(content)) {
                    for (String s : content) {
                        FileUtils.write(file, s, "UTF-8", true);
                        FileUtils.write(file, "\n\n", "UTF-8", true);
                    }
                }
            }
        }
    }
}
